#include <stdio.h>  
#include <stdlib.h>  
#include <ctype.h>  
  
int main() {  
    FILE *fp;  
    char str[129];  
    int i;  
  
  
    // 写入整数数据  
    fp = fopen("demo_char.bin", "w");  
    if (!fp) {  
        perror("Failed to open file for writing integers");  
        return EXIT_FAILURE;  
    }  
    for (i = 0; i < 128; i++) {  
        fwrite(&i, sizeof(int), 1, fp);  
    }  
    fclose(fp);  
  
    // 从字符文件中读取数据  
    if ((fp = fopen("demo_char.bin", "r")) == NULL) {  
        printf("fail\n");  
        return EXIT_FAILURE;  
    }  
    char ch;  
    for (i = 0; i < 128; i++) {  
        if (isprint(i)) printf("%c\t", i);  
        else printf("%d\t", i);  
        if (i%10==0)putchar(10);
        
    }  
    fclose(fp);  
  
    return 0;  
}